<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>&lt;GVariant&gt;: </title>
<meta name="generator" content="DocBook XSL Stylesheets V1.79.2">
<link rel="home" href="index.html" title="">
<link rel="up" href="ch01.html" title="GLib">
<link rel="prev" href="re82.html" title="&lt;%GLibUserDirectory&gt;">
<link rel="next" href="re84.html" title="&lt;GVariantBuilder&gt;">
<meta name="generator" content="GTK-Doc V1.33.1 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle">
<td width="100%" align="left" class="shortcuts"></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
<td><img src="up-insensitive.png" width="16" height="16" border="0"></td>
<td><a accesskey="p" href="re82.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
<td><a accesskey="n" href="re84.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
</tr></table>
<div class="refentry">
<a name="id-1.1.84"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2>&lt;GVariant&gt;</h2>
<p>&lt;GVariant&gt;</p>
</div>
<div class="refsect1">
<a name="id-1.1.84.2"></a><h2>Description</h2>
<p><span class="type">GVariant</span> is a variant datatype; it can contain one or more values
along with information about the type of the values.
</p>
<p>A <span class="type">GVariant</span> may contain simple types, like an integer, or a boolean value;
or complex types, like an array of two strings, or a dictionary of key
value pairs. A <span class="type">GVariant</span> is also immutable: once it's been created neither
its type nor its content can be modified further.
</p>
<p>GVariant is useful whenever data needs to be serialized, for example when
sending method parameters in DBus, or when saving settings using GSettings.
</p>
<p>When creating a new <span class="type">GVariant</span>, you pass the data you want to store in it
along with a string representing the type of data you wish to pass to it.
</p>
<p>For instance, if you want to create a <span class="type">GVariant</span> holding an integer value you
can use:
</p>
<div class="informalexample"><pre class="programlisting">
  GVariant *v = g_variant_new ("u", 40);
</pre></div>

<p>The string "u" in the first argument tells <span class="type">GVariant</span> that the data passed to
the constructor (40) is going to be an unsigned integer.
</p>
<p>More advanced examples of <span class="type">GVariant</span> in use can be found in documentation for
[GVariant format strings][gvariant-format-strings-pointers].
</p>
<p>The range of possible values is determined by the type.
</p>
<p>The type system used by <span class="type">GVariant</span> is <span class="type">GVariantType</span>.
</p>
<p><span class="type">GVariant</span> instances always have a type and a value (which are given
at construction time).  The type and value of a <span class="type">GVariant</span> instance
can never change other than by the <span class="type">GVariant</span> itself being
destroyed.  A <span class="type">GVariant</span> cannot contain a pointer.
</p>
<p><span class="type">GVariant</span> is reference counted using <code class="function">g_variant_ref()</code> and
<code class="function">g_variant_unref()</code>.  <span class="type">GVariant</span> also has floating reference counts --
see <code class="function">g_variant_ref_sink()</code>.
</p>
<p><span class="type">GVariant</span> is completely threadsafe.  A <span class="type">GVariant</span> instance can be
concurrently accessed in any way from any number of threads without
problems.
</p>
<p><span class="type">GVariant</span> is heavily optimised for dealing with data in serialised
form.  It works particularly well with data located in memory-mapped
files.  It can perform nearly all deserialisation operations in a
small constant time, usually touching only a single memory page.
Serialised <span class="type">GVariant</span> data can also be sent over the network.
</p>
<p><span class="type">GVariant</span> is largely compatible with D-Bus.  Almost all types of
<span class="type">GVariant</span> instances can be sent over D-Bus.  See <span class="type">GVariantType</span> for
exceptions.  (However, <span class="type">GVariant</span>'s serialisation format is not the same
as the serialisation format of a D-Bus message body: use <span class="type">GDBusMessage</span>,
in the gio library, for those.)
</p>
<p>For space-efficiency, the <span class="type">GVariant</span> serialisation format does not
automatically include the variant's length, type or endianness,
which must either be implied from context (such as knowledge that a
particular file format always contains a little-endian
<code class="constant">G_VARIANT_TYPE_VARIANT</code> which occupies the whole length of the file)
or supplied out-of-band (for instance, a length, type and/or endianness
indicator could be placed at the beginning of a file, network message
or network stream).
</p>
<p>A <span class="type">GVariant</span>'s size is limited mainly by any lower level operating
system constraints, such as the number of bits in <span class="type">gsize</span>.  For
example, it is reasonable to have a 2GB file mapped into memory
with <span class="type">GMappedFile</span>, and call <code class="function">g_variant_new_from_data()</code> on it.
</p>
<p>For convenience to C programmers, <span class="type">GVariant</span> features powerful
varargs-based value construction and destruction.  This feature is
designed to be embedded in other libraries.
</p>
<p>There is a Python-inspired text language for describing <span class="type">GVariant</span>
values.  <span class="type">GVariant</span> includes a printer for this language and a parser
with type inferencing.
</p>
<div class="refsect2">
<a name="id-1.1.84.2.21"></a><h3>Memory Use</h3>
<p><span class="type">GVariant</span> tries to be quite efficient with respect to memory use.
This section gives a rough idea of how much memory is used by the
current implementation.  The information here is subject to change
in the future.
</p>
<p>The memory allocated by <span class="type">GVariant</span> can be grouped into 4 broad
purposes: memory for serialised data, memory for the type
information cache, buffer management memory and memory for the
<span class="type">GVariant</span> structure itself.
</p>
</div>
<div class="refsect2">
<a name="id-1.1.84.2.22"></a><h3>Serialised Data Memory</h3>
<p>This is the memory that is used for storing GVariant data in
serialised form.  This is what would be sent over the network or
what would end up on disk, not counting any indicator of the
endianness, or of the length or type of the top-level variant.
</p>
<p>The amount of memory required to store a boolean is 1 byte. 16,
32 and 64 bit integers and double precision floating point numbers
use their "natural" size.  Strings (including object path and
signature strings) are stored with a nul terminator, and as such
use the length of the string plus 1 byte.
</p>
<p>Maybe types use no space at all to represent the null value and
use the same amount of space (sometimes plus one byte) as the
equivalent non-maybe-typed value to represent the non-null case.
</p>
<p>Arrays use the amount of space required to store each of their
members, concatenated.  Additionally, if the items stored in an
array are not of a fixed-size (ie: strings, other arrays, etc)
then an additional framing offset is stored for each item.  The
size of this offset is either 1, 2 or 4 bytes depending on the
overall size of the container.  Additionally, extra padding bytes
are added as required for alignment of child values.
</p>
<p>Tuples (including dictionary entries) use the amount of space
required to store each of their members, concatenated, plus one
framing offset (as per arrays) for each non-fixed-sized item in
the tuple, except for the last one.  Additionally, extra padding
bytes are added as required for alignment of child values.
</p>
<p>Variants use the same amount of space as the item inside of the
variant, plus 1 byte, plus the length of the type string for the
item inside the variant.
</p>
<p>As an example, consider a dictionary mapping strings to variants.
In the case that the dictionary is empty, 0 bytes are required for
the serialisation.
</p>
<p>If we add an item "width" that maps to the int32 value of 500 then
we will use 4 byte to store the int32 (so 6 for the variant
containing it) and 6 bytes for the string.  The variant must be
aligned to 8 after the 6 bytes of the string, so that's 2 extra
bytes.  6 (string) + 2 (padding) + 6 (variant) is 14 bytes used
for the dictionary entry.  An additional 1 byte is added to the
array as a framing offset making a total of 15 bytes.
</p>
<p>If we add another entry, "title" that maps to a nullable string
that happens to have a value of null, then we use 0 bytes for the
null value (and 3 bytes for the variant to contain it along with
its type string) plus 6 bytes for the string.  Again, we need 2
padding bytes.  That makes a total of 6 + 2 + 3 = 11 bytes.
</p>
<p>We now require extra padding between the two items in the array.
After the 14 bytes of the first item, that's 2 bytes required.
We now require 2 framing offsets for an extra two
bytes. 14 + 2 + 11 + 2 = 29 bytes to encode the entire two-item
dictionary.
</p>
</div>
<div class="refsect2">
<a name="id-1.1.84.2.23"></a><h3>Type Information Cache</h3>
<p>For each GVariant type that currently exists in the program a type
information structure is kept in the type information cache.  The
type information structure is required for rapid deserialisation.
</p>
<p>Continuing with the above example, if a <span class="type">GVariant</span> exists with the
type "a{sv}" then a type information struct will exist for
"a{sv}", "{sv}", "s", and "v".  Multiple uses of the same type
will share the same type information.  Additionally, all
single-digit types are stored in read-only static memory and do
not contribute to the writable memory footprint of a program using
<span class="type">GVariant</span>.
</p>
<p>Aside from the type information structures stored in read-only
memory, there are two forms of type information.  One is used for
container types where there is a single element type: arrays and
maybe types.  The other is used for container types where there
are multiple element types: tuples and dictionary entries.
</p>
<p>Array type info structures are 6 * sizeof (void *), plus the
memory required to store the type string itself.  This means that
on 32-bit systems, the cache entry for "a{sv}" would require 30
bytes of memory (plus malloc overhead).
</p>
<p>Tuple type info structures are 6 * sizeof (void *), plus 4 *
sizeof (void *) for each item in the tuple, plus the memory
required to store the type string itself.  A 2-item tuple, for
example, would have a type information structure that consumed
writable memory in the size of 14 * sizeof (void *) (plus type
string)  This means that on 32-bit systems, the cache entry for
"{sv}" would require 61 bytes of memory (plus malloc overhead).
</p>
<p>This means that in total, for our "a{sv}" example, 91 bytes of
type information would be allocated.
</p>
<p>The type information cache, additionally, uses a <span class="type">GHashTable</span> to
store and look up the cached items and stores a pointer to this
hash table in static storage.  The hash table is freed when there
are zero items in the type cache.
</p>
<p>Although these sizes may seem large it is important to remember
that a program will probably only have a very small number of
different types of values in it and that only one type information
structure is required for many different values of the same type.
</p>
</div>
<div class="refsect2">
<a name="id-1.1.84.2.24"></a><h3>Buffer Management Memory</h3>
<p><span class="type">GVariant</span> uses an internal buffer management structure to deal
with the various different possible sources of serialised data
that it uses.  The buffer is responsible for ensuring that the
correct call is made when the data is no longer in use by
<span class="type">GVariant</span>.  This may involve a <code class="function">g_free()</code> or a <code class="function">g_slice_free()</code> or
even <code class="function">g_mapped_file_unref()</code>.
</p>
<p>One buffer management structure is used for each chunk of
serialised data.  The size of the buffer management structure
is 4 * (void *).  On 32-bit systems, that's 16 bytes.
</p>
</div>
<div class="refsect2">
<a name="id-1.1.84.2.25"></a><h3>GVariant structure</h3>
<p>The size of a <span class="type">GVariant</span> structure is 6 * (void *).  On 32-bit
systems, that's 24 bytes.
</p>
<p><span class="type">GVariant</span> structures only exist if they are explicitly created
with API calls.  For example, if a <span class="type">GVariant</span> is constructed out of
serialised data for the example given above (with the dictionary)
then although there are 9 individual values that comprise the
entire dictionary (two keys, two values, two variants containing
the values, two dictionary entries, plus the dictionary itself),
only 1 <span class="type">GVariant</span> instance exists -- the one referring to the
dictionary.
</p>
<p>If calls are made to start accessing the other values then
<span class="type">GVariant</span> instances will exist for those values only for as long
as they are in use (ie: until you call <code class="function">g_variant_unref()</code>).  The
type information is shared.  The serialised data and the buffer
management structure for that serialised data is shared by the
child.
</p>
</div>
<div class="refsect2">
<a name="id-1.1.84.2.26"></a><h3>Summary</h3>
<p>To put the entire example together, for our dictionary mapping
strings to variants (with two entries, as given above), we are
using 91 bytes of memory for type information, 29 bytes of memory
for the serialised data, 16 bytes for buffer management and 24
bytes for the <span class="type">GVariant</span> instance, or a total of 160 bytes, plus
malloc overhead.  If we were to use <code class="function">g_variant_get_child_value()</code> to
access the two dictionary entries, we would use an additional 48
bytes.  If we were to have other dictionaries of the same type, we
would use more memory for the serialised data and buffer
management for those dictionaries, but the type information would
be shared.</p>
</div>
</div>
<div class="refsect1">
<a name="id-1.1.84.3"></a><h2>Functions</h2>
<div class="refsect2">
<a name="id-1.1.84.3.2"></a><h3>byteswap</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:byteswap self))
</pre></div>
<p>Performs a byteswapping operation on the contents of <em class="parameter"><code>value</code></em>.  The
result is that all multi-byte numeric data contained in <em class="parameter"><code>value</code></em> is
byteswapped.  That includes 16, 32, and 64bit signed and unsigned
integers as well as file handles and double precision floating point
values.
</p>
<p>This function is an identity mapping on any value that does not
contain multi-byte numeric data.  That include strings, booleans,
bytes and containers containing only these things (recursively).
</p>
<p>The returned value is always in normal form and is marked as trusted.</p>
<div class="refsect3">
<a name="id-1.1.84.3.2.6"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>a <span class="type">GVariant</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.3"></a><h3>check-format-string?</h3>
<div class="informalexample"><pre class="programlisting">(define-values
  (%return)
  (variant:check-format-string? self format-string copy-only))
</pre></div>
<p>Checks if calling <code class="function">g_variant_get()</code> with <em class="parameter"><code>format_string</code></em> on <em class="parameter"><code>value</code></em> would
be valid from a type-compatibility standpoint.  <em class="parameter"><code>format_string</code></em> is
assumed to be a valid format string (from a syntactic standpoint).
</p>
<p>If <em class="parameter"><code>copy_only</code></em> is <code class="constant">TRUE</code> then this function additionally checks that it
would be safe to call <code class="function">g_variant_unref()</code> on <em class="parameter"><code>value</code></em> immediately after
the call to <code class="function">g_variant_get()</code> without invalidating the result.  This is
only possible if deep copies are made (ie: there are no pointers to
the data inside of the soon-to-be-freed <span class="type">GVariant</span> instance).  If this
check fails then a <code class="function">g_critical()</code> is printed and <code class="constant">FALSE</code> is returned.
</p>
<p>This function is meant to be used by functions that wish to provide
varargs accessors to <span class="type">GVariant</span> values of uncertain values (eg:
<code class="function">g_variant_lookup()</code> or <code class="function">g_menu_model_get_item_attribute()</code>).</p>
<div class="refsect3">
<a name="id-1.1.84.3.3.6"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>a <span class="type">GVariant</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>format_string</p></td>
<td class="parameter_description">
<p>a valid <span class="type">GVariant</span> format string</p>
<p>Passed as <code class="code">format-string</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>copy_only</p></td>
<td class="parameter_description">
<p><code class="constant">TRUE</code> to ensure the format string makes deep copies</p>
<p>Passed as <code class="code">copy-only</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.4"></a><h3>classify</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:classify self))
</pre></div>
<p>Classifies <em class="parameter"><code>value</code></em> according to its top-level type.</p>
<div class="refsect3">
<a name="id-1.1.84.3.4.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>a <span class="type">GVariant</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.5"></a><h3>compare</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:compare self two))
</pre></div>
<p>Compares <em class="parameter"><code>one</code></em> and <em class="parameter"><code>two</code></em>.
</p>
<p>The types of <em class="parameter"><code>one</code></em> and <em class="parameter"><code>two</code></em> are <span class="type">gconstpointer</span> only to allow use of
this function with <span class="type">GTree</span>, <span class="type">GPtrArray</span>, etc.  They must each be a
<span class="type">GVariant</span>.
</p>
<p>Comparison is only defined for basic types (ie: booleans, numbers,
strings).  For booleans, <code class="constant">FALSE</code> is less than <code class="constant">TRUE</code>.  Numbers are
ordered in the usual way.  Strings are in ASCII lexographical order.
</p>
<p>It is a programmer error to attempt to compare container values or
two values that have types that are not exactly equal.  For example,
you cannot compare a 32-bit signed integer with a 32-bit unsigned
integer.  Also note that this function is not particularly
well-behaved when it comes to comparison of doubles; in particular,
the handling of incomparable values (ie: NaN) is undefined.
</p>
<p>If you only require an equality comparison, <code class="function">g_variant_equal()</code> is more
general.</p>
<div class="refsect3">
<a name="id-1.1.84.3.5.8"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>one</p></td>
<td class="parameter_description">
<p>a basic-typed <span class="type">GVariant</span> instance</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>two</p></td>
<td class="parameter_description">
<p>a <span class="type">GVariant</span> instance of the same type</p>
<p>Passed as <code class="code">two</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.6"></a><h3>dup-bytestring</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return length) (variant:dup-bytestring self))
</pre></div>
<p>Similar to <code class="function">g_variant_get_bytestring()</code> except that instead of
returning a constant string, the string is duplicated.
</p>
<p>The return value must be freed using <code class="function">g_free()</code>.</p>
<div class="refsect3">
<a name="id-1.1.84.3.6.5"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>an array-of-bytes <span class="type">GVariant</span> instance</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>length</p></td>
<td class="parameter_description">
<p>a pointer to a <span class="type">gsize</span>, to store
         the length (not including the nul terminator)</p>
<p>Inferred from <code class="code">%return</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.7"></a><h3>dup-bytestring-array</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return length) (variant:dup-bytestring-array self))
</pre></div>
<p>Gets the contents of an array of array of bytes <span class="type">GVariant</span>.  This call
makes a deep copy; the return result should be released with
<code class="function">g_strfreev()</code>.
</p>
<p>If <em class="parameter"><code>length</code></em> is non-<code class="constant">NULL</code> then the number of elements in the result is
stored there.  In any case, the resulting array will be
<code class="constant">NULL</code>-terminated.
</p>
<p>For an empty array, <em class="parameter"><code>length</code></em> will be set to 0 and a pointer to a
<code class="constant">NULL</code> pointer will be returned.</p>
<div class="refsect3">
<a name="id-1.1.84.3.7.6"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>an array of array of bytes <span class="type">GVariant</span> ('aay')</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>length</p></td>
<td class="parameter_description">
<p>the length of the result, or <code class="constant">NULL</code></p>
<p>Inferred from <code class="code">%return</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.8"></a><h3>dup-objv</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return length) (variant:dup-objv self))
</pre></div>
<p>Gets the contents of an array of object paths <span class="type">GVariant</span>.  This call
makes a deep copy; the return result should be released with
<code class="function">g_strfreev()</code>.
</p>
<p>If <em class="parameter"><code>length</code></em> is non-<code class="constant">NULL</code> then the number of elements in the result
is stored there.  In any case, the resulting array will be
<code class="constant">NULL</code>-terminated.
</p>
<p>For an empty array, <em class="parameter"><code>length</code></em> will be set to 0 and a pointer to a
<code class="constant">NULL</code> pointer will be returned.</p>
<div class="refsect3">
<a name="id-1.1.84.3.8.6"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>an array of object paths <span class="type">GVariant</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>length</p></td>
<td class="parameter_description">
<p>the length of the result, or <code class="constant">NULL</code></p>
<p>Inferred from <code class="code">%return</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.9"></a><h3>dup-string</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return length) (variant:dup-string self))
</pre></div>
<p>Similar to <code class="function">g_variant_get_string()</code> except that instead of returning
a constant string, the string is duplicated.
</p>
<p>The string will always be UTF-8 encoded.
</p>
<p>The return value must be freed using <code class="function">g_free()</code>.</p>
<div class="refsect3">
<a name="id-1.1.84.3.9.6"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>a string <span class="type">GVariant</span> instance</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>length</p></td>
<td class="parameter_description">
<p>a pointer to a <span class="type">gsize</span>, to store the length</p>
<p>Passed as <code class="code">length</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.10"></a><h3>dup-strv</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return length) (variant:dup-strv self))
</pre></div>
<p>Gets the contents of an array of strings <span class="type">GVariant</span>.  This call
makes a deep copy; the return result should be released with
<code class="function">g_strfreev()</code>.
</p>
<p>If <em class="parameter"><code>length</code></em> is non-<code class="constant">NULL</code> then the number of elements in the result
is stored there.  In any case, the resulting array will be
<code class="constant">NULL</code>-terminated.
</p>
<p>For an empty array, <em class="parameter"><code>length</code></em> will be set to 0 and a pointer to a
<code class="constant">NULL</code> pointer will be returned.</p>
<div class="refsect3">
<a name="id-1.1.84.3.10.6"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>an array of strings <span class="type">GVariant</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>length</p></td>
<td class="parameter_description">
<p>the length of the result, or <code class="constant">NULL</code></p>
<p>Inferred from <code class="code">%return</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.11"></a><h3>equal?</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:equal? self two))
</pre></div>
<p>Checks if <em class="parameter"><code>one</code></em> and <em class="parameter"><code>two</code></em> have the same type and value.
</p>
<p>The types of <em class="parameter"><code>one</code></em> and <em class="parameter"><code>two</code></em> are <span class="type">gconstpointer</span> only to allow use of
this function with <span class="type">GHashTable</span>.  They must each be a <span class="type">GVariant</span>.</p>
<div class="refsect3">
<a name="id-1.1.84.3.11.5"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>one</p></td>
<td class="parameter_description">
<p>a <span class="type">GVariant</span> instance</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>two</p></td>
<td class="parameter_description">
<p>a <span class="type">GVariant</span> instance</p>
<p>Passed as <code class="code">two</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.12"></a><h3>get-boolean?</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-boolean? self))
</pre></div>
<p>Returns the boolean value of <em class="parameter"><code>value</code></em>.
</p>
<p>It is an error to call this function with a <em class="parameter"><code>value</code></em> of any type
other than <code class="constant">G_VARIANT_TYPE_BOOLEAN</code>.</p>
<div class="refsect3">
<a name="id-1.1.84.3.12.5"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>a boolean <span class="type">GVariant</span> instance</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.13"></a><h3>get-byte</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-byte self))
</pre></div>
<p>Returns the byte value of <em class="parameter"><code>value</code></em>.
</p>
<p>It is an error to call this function with a <em class="parameter"><code>value</code></em> of any type
other than <code class="constant">G_VARIANT_TYPE_BYTE</code>.</p>
<div class="refsect3">
<a name="id-1.1.84.3.13.5"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>a byte <span class="type">GVariant</span> instance</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.14"></a><h3>get-bytestring</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-bytestring self))
</pre></div>
<p>Returns the string value of a <span class="type">GVariant</span> instance with an
array-of-bytes type.  The string has no particular encoding.
</p>
<p>If the array does not end with a nul terminator character, the empty
string is returned.  For this reason, you can always trust that a
non-<code class="constant">NULL</code> nul-terminated string will be returned by this function.
</p>
<p>If the array contains a nul terminator character somewhere other than
the last byte then the returned string is the string, up to the first
such nul character.
</p>
<p><code class="function">g_variant_get_fixed_array()</code> should be used instead if the array contains
arbitrary data that could not be nul-terminated or could contain nul bytes.
</p>
<p>It is an error to call this function with a <em class="parameter"><code>value</code></em> that is not an
array of bytes.
</p>
<p>The return value remains valid as long as <em class="parameter"><code>value</code></em> exists.</p>
<div class="refsect3">
<a name="id-1.1.84.3.14.9"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>an array-of-bytes <span class="type">GVariant</span> instance</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.15"></a><h3>get-bytestring-array</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return length) (variant:get-bytestring-array self))
</pre></div>
<p>Gets the contents of an array of array of bytes <span class="type">GVariant</span>.  This call
makes a shallow copy; the return result should be released with
<code class="function">g_free()</code>, but the individual strings must not be modified.
</p>
<p>If <em class="parameter"><code>length</code></em> is non-<code class="constant">NULL</code> then the number of elements in the result is
stored there.  In any case, the resulting array will be
<code class="constant">NULL</code>-terminated.
</p>
<p>For an empty array, <em class="parameter"><code>length</code></em> will be set to 0 and a pointer to a
<code class="constant">NULL</code> pointer will be returned.</p>
<div class="refsect3">
<a name="id-1.1.84.3.15.6"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>an array of array of bytes <span class="type">GVariant</span> ('aay')</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>length</p></td>
<td class="parameter_description">
<p>the length of the result, or <code class="constant">NULL</code></p>
<p>Inferred from <code class="code">%return</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.16"></a><h3>get-child-value</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-child-value self index-))
</pre></div>
<p>Reads a child item out of a container <span class="type">GVariant</span> instance.  This
includes variants, maybes, arrays, tuples and dictionary
entries.  It is an error to call this function on any other type of
<span class="type">GVariant</span>.
</p>
<p>It is an error if <em class="parameter"><code>index_</code></em> is greater than the number of child items
in the container.  See <code class="function">g_variant_n_children()</code>.
</p>
<p>The returned value is never floating.  You should free it with
<code class="function">g_variant_unref()</code> when you're done with it.
</p>
<p>Note that values borrowed from the returned child are not guaranteed to
still be valid after the child is freed even if you still hold a reference
to <em class="parameter"><code>value</code></em>, if <em class="parameter"><code>value</code></em> has not been serialised at the time this function is
called. To avoid this, you can serialize <em class="parameter"><code>value</code></em> by calling
<code class="function">g_variant_get_data()</code> and optionally ignoring the return value.
</p>
<p>There may be implementation specific restrictions on deeply nested values,
which would result in the unit tuple being returned as the child value,
instead of further nested children. <span class="type">GVariant</span> is guaranteed to handle
nesting up to at least 64 levels.
</p>
<p>This function is O(1).</p>
<div class="refsect3">
<a name="id-1.1.84.3.16.9"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>a container <span class="type">GVariant</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>index_</p></td>
<td class="parameter_description">
<p>the index of the child to fetch</p>
<p>Passed as <code class="code">index-</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.17"></a><h3>get-data</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-data self))
</pre></div>
<p>Returns a pointer to the serialised form of a <span class="type">GVariant</span> instance.
The returned data may not be in fully-normalised form if read from an
untrusted source.  The returned data must not be freed; it remains
valid for as long as <em class="parameter"><code>value</code></em> exists.
</p>
<p>If <em class="parameter"><code>value</code></em> is a fixed-sized value that was deserialised from a
corrupted serialised container then <code class="constant">NULL</code> may be returned.  In this
case, the proper thing to do is typically to use the appropriate
number of nul bytes in place of <em class="parameter"><code>value</code></em>.  If <em class="parameter"><code>value</code></em> is not fixed-sized
then <code class="constant">NULL</code> is never returned.
</p>
<p>In the case that <em class="parameter"><code>value</code></em> is already in serialised form, this function
is O(1).  If the value is not already in serialised form,
serialisation occurs implicitly and is approximately O(n) in the size
of the result.
</p>
<p>To deserialise the data returned by this function, in addition to the
serialised data, you must know the type of the <span class="type">GVariant</span>, and (if the
machine might be different) the endianness of the machine that stored
it. As a result, file formats or network messages that incorporate
serialised <span class="type">GVariants</span> must include this information either
implicitly (for instance "the file always contains a
<code class="constant">G_VARIANT_TYPE_VARIANT</code> and it is always in little-endian order") or
explicitly (by storing the type and/or endianness in addition to the
serialised data).</p>
<div class="refsect3">
<a name="id-1.1.84.3.17.7"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>a <span class="type">GVariant</span> instance</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.18"></a><h3>get-data-as-bytes</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-data-as-bytes self))
</pre></div>
<p>Returns a pointer to the serialised form of a <span class="type">GVariant</span> instance.
The semantics of this function are exactly the same as
<code class="function">g_variant_get_data()</code>, except that the returned <span class="type">GBytes</span> holds
a reference to the variant data.</p>
<div class="refsect3">
<a name="id-1.1.84.3.18.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>a <span class="type">GVariant</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.19"></a><h3>get-double</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-double self))
</pre></div>
<p>Returns the double precision floating point value of <em class="parameter"><code>value</code></em>.
</p>
<p>It is an error to call this function with a <em class="parameter"><code>value</code></em> of any type
other than <code class="constant">G_VARIANT_TYPE_DOUBLE</code>.</p>
<div class="refsect3">
<a name="id-1.1.84.3.19.5"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>a double <span class="type">GVariant</span> instance</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.20"></a><h3>get-handle</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-handle self))
</pre></div>
<p>Returns the 32-bit signed integer value of <em class="parameter"><code>value</code></em>.
</p>
<p>It is an error to call this function with a <em class="parameter"><code>value</code></em> of any type other
than <code class="constant">G_VARIANT_TYPE_HANDLE</code>.
</p>
<p>By convention, handles are indexes into an array of file descriptors
that are sent alongside a D-Bus message.  If you're not interacting
with D-Bus, you probably don't need them.</p>
<div class="refsect3">
<a name="id-1.1.84.3.20.6"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>a handle <span class="type">GVariant</span> instance</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.21"></a><h3>get-int16</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-int16 self))
</pre></div>
<p>Returns the 16-bit signed integer value of <em class="parameter"><code>value</code></em>.
</p>
<p>It is an error to call this function with a <em class="parameter"><code>value</code></em> of any type
other than <code class="constant">G_VARIANT_TYPE_INT16</code>.</p>
<div class="refsect3">
<a name="id-1.1.84.3.21.5"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>an int16 <span class="type">GVariant</span> instance</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.22"></a><h3>get-int32</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-int32 self))
</pre></div>
<p>Returns the 32-bit signed integer value of <em class="parameter"><code>value</code></em>.
</p>
<p>It is an error to call this function with a <em class="parameter"><code>value</code></em> of any type
other than <code class="constant">G_VARIANT_TYPE_INT32</code>.</p>
<div class="refsect3">
<a name="id-1.1.84.3.22.5"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>an int32 <span class="type">GVariant</span> instance</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.23"></a><h3>get-int64</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-int64 self))
</pre></div>
<p>Returns the 64-bit signed integer value of <em class="parameter"><code>value</code></em>.
</p>
<p>It is an error to call this function with a <em class="parameter"><code>value</code></em> of any type
other than <code class="constant">G_VARIANT_TYPE_INT64</code>.</p>
<div class="refsect3">
<a name="id-1.1.84.3.23.5"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>an int64 <span class="type">GVariant</span> instance</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.24"></a><h3>get-maybe</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-maybe self))
</pre></div>
<p>Given a maybe-typed <span class="type">GVariant</span> instance, extract its value.  If the
value is Nothing, then this function returns <code class="constant">NULL</code>.</p>
<div class="refsect3">
<a name="id-1.1.84.3.24.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>a maybe-typed value</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.25"></a><h3>get-normal-form</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-normal-form self))
</pre></div>
<p>Gets a <span class="type">GVariant</span> instance that has the same value as <em class="parameter"><code>value</code></em> and is
trusted to be in normal form.
</p>
<p>If <em class="parameter"><code>value</code></em> is already trusted to be in normal form then a new
reference to <em class="parameter"><code>value</code></em> is returned.
</p>
<p>If <em class="parameter"><code>value</code></em> is not already trusted, then it is scanned to check if it
is in normal form.  If it is found to be in normal form then it is
marked as trusted and a new reference to it is returned.
</p>
<p>If <em class="parameter"><code>value</code></em> is found not to be in normal form then a new trusted
<span class="type">GVariant</span> is created with the same value as <em class="parameter"><code>value</code></em>.
</p>
<p>It makes sense to call this function if you've received <span class="type">GVariant</span>
data from untrusted sources and you want to ensure your serialised
output is definitely in normal form.
</p>
<p>If <em class="parameter"><code>value</code></em> is already in normal form, a new reference will be returned
(which will be floating if <em class="parameter"><code>value</code></em> is floating). If it is not in normal form,
the newly created <span class="type">GVariant</span> will be returned with a single non-floating
reference. Typically, <code class="function">g_variant_take_ref()</code> should be called on the return
value from this function to guarantee ownership of a single non-floating
reference to it.</p>
<div class="refsect3">
<a name="id-1.1.84.3.25.9"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>a <span class="type">GVariant</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.26"></a><h3>get-objv</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return length) (variant:get-objv self))
</pre></div>
<p>Gets the contents of an array of object paths <span class="type">GVariant</span>.  This call
makes a shallow copy; the return result should be released with
<code class="function">g_free()</code>, but the individual strings must not be modified.
</p>
<p>If <em class="parameter"><code>length</code></em> is non-<code class="constant">NULL</code> then the number of elements in the result
is stored there.  In any case, the resulting array will be
<code class="constant">NULL</code>-terminated.
</p>
<p>For an empty array, <em class="parameter"><code>length</code></em> will be set to 0 and a pointer to a
<code class="constant">NULL</code> pointer will be returned.</p>
<div class="refsect3">
<a name="id-1.1.84.3.26.6"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>an array of object paths <span class="type">GVariant</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>length</p></td>
<td class="parameter_description">
<p>the length of the result, or <code class="constant">NULL</code></p>
<p>Inferred from <code class="code">%return</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.27"></a><h3>get-size</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-size self))
</pre></div>
<p>Determines the number of bytes that would be required to store <em class="parameter"><code>value</code></em>
with <code class="function">g_variant_store()</code>.
</p>
<p>If <em class="parameter"><code>value</code></em> has a fixed-sized type then this function always returned
that fixed size.
</p>
<p>In the case that <em class="parameter"><code>value</code></em> is already in serialised form or the size has
already been calculated (ie: this function has been called before)
then this function is O(1).  Otherwise, the size is calculated, an
operation which is approximately O(n) in the number of values
involved.</p>
<div class="refsect3">
<a name="id-1.1.84.3.27.6"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>a <span class="type">GVariant</span> instance</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.28"></a><h3>get-string</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return length) (variant:get-string self))
</pre></div>
<p>Returns the string value of a <span class="type">GVariant</span> instance with a string
type.  This includes the types <code class="constant">G_VARIANT_TYPE_STRING</code>,
<code class="constant">G_VARIANT_TYPE_OBJECT_PATH</code> and <code class="constant">G_VARIANT_TYPE_SIGNATURE</code>.
</p>
<p>The string will always be UTF-8 encoded, will never be <code class="constant">NULL</code>, and will never
contain nul bytes.
</p>
<p>If <em class="parameter"><code>length</code></em> is non-<code class="constant">NULL</code> then the length of the string (in bytes) is
returned there.  For trusted values, this information is already
known.  Untrusted values will be validated and, if valid, a <code class="function">strlen()</code> will be
performed. If invalid, a default value will be returned — for
<code class="constant">G_VARIANT_TYPE_OBJECT_PATH</code>, this is <code class="code">"/"</code>, and for other types it is the
empty string.
</p>
<p>It is an error to call this function with a <em class="parameter"><code>value</code></em> of any type
other than those three.
</p>
<p>The return value remains valid as long as <em class="parameter"><code>value</code></em> exists.</p>
<div class="refsect3">
<a name="id-1.1.84.3.28.8"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>a string <span class="type">GVariant</span> instance</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>length</p></td>
<td class="parameter_description">
<p>a pointer to a <span class="type">gsize</span>,
         to store the length</p>
<p>Passed as <code class="code">length</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.29"></a><h3>get-strv</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return length) (variant:get-strv self))
</pre></div>
<p>Gets the contents of an array of strings <span class="type">GVariant</span>.  This call
makes a shallow copy; the return result should be released with
<code class="function">g_free()</code>, but the individual strings must not be modified.
</p>
<p>If <em class="parameter"><code>length</code></em> is non-<code class="constant">NULL</code> then the number of elements in the result
is stored there.  In any case, the resulting array will be
<code class="constant">NULL</code>-terminated.
</p>
<p>For an empty array, <em class="parameter"><code>length</code></em> will be set to 0 and a pointer to a
<code class="constant">NULL</code> pointer will be returned.</p>
<div class="refsect3">
<a name="id-1.1.84.3.29.6"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>an array of strings <span class="type">GVariant</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>length</p></td>
<td class="parameter_description">
<p>the length of the result, or <code class="constant">NULL</code></p>
<p>Inferred from <code class="code">%return</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.30"></a><h3>get-type</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-type self))
</pre></div>
<p>Determines the type of <em class="parameter"><code>value</code></em>.
</p>
<p>The return value is valid for the lifetime of <em class="parameter"><code>value</code></em> and must not
be freed.</p>
<div class="refsect3">
<a name="id-1.1.84.3.30.5"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>a <span class="type">GVariant</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.31"></a><h3>get-type-string</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-type-string self))
</pre></div>
<p>Returns the type string of <em class="parameter"><code>value</code></em>.  Unlike the result of calling
<code class="function">g_variant_type_peek_string()</code>, this string is nul-terminated.  This
string belongs to <span class="type">GVariant</span> and must not be freed.</p>
<div class="refsect3">
<a name="id-1.1.84.3.31.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>a <span class="type">GVariant</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.32"></a><h3>get-uint16</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-uint16 self))
</pre></div>
<p>Returns the 16-bit unsigned integer value of <em class="parameter"><code>value</code></em>.
</p>
<p>It is an error to call this function with a <em class="parameter"><code>value</code></em> of any type
other than <code class="constant">G_VARIANT_TYPE_UINT16</code>.</p>
<div class="refsect3">
<a name="id-1.1.84.3.32.5"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>a uint16 <span class="type">GVariant</span> instance</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.33"></a><h3>get-uint32</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-uint32 self))
</pre></div>
<p>Returns the 32-bit unsigned integer value of <em class="parameter"><code>value</code></em>.
</p>
<p>It is an error to call this function with a <em class="parameter"><code>value</code></em> of any type
other than <code class="constant">G_VARIANT_TYPE_UINT32</code>.</p>
<div class="refsect3">
<a name="id-1.1.84.3.33.5"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>a uint32 <span class="type">GVariant</span> instance</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.34"></a><h3>get-uint64</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-uint64 self))
</pre></div>
<p>Returns the 64-bit unsigned integer value of <em class="parameter"><code>value</code></em>.
</p>
<p>It is an error to call this function with a <em class="parameter"><code>value</code></em> of any type
other than <code class="constant">G_VARIANT_TYPE_UINT64</code>.</p>
<div class="refsect3">
<a name="id-1.1.84.3.34.5"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>a uint64 <span class="type">GVariant</span> instance</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.35"></a><h3>get-variant</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:get-variant self))
</pre></div>
<p>Unboxes <em class="parameter"><code>value</code></em>.  The result is the <span class="type">GVariant</span> instance that was
contained in <em class="parameter"><code>value</code></em>.</p>
<div class="refsect3">
<a name="id-1.1.84.3.35.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>a variant <span class="type">GVariant</span> instance</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.36"></a><h3>hash</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:hash self))
</pre></div>
<p>Generates a hash value for a <span class="type">GVariant</span> instance.
</p>
<p>The output of this function is guaranteed to be the same for a given
value only per-process.  It may change between different processor
architectures or even different versions of GLib.  Do not use this
function as a basis for building protocols or file formats.
</p>
<p>The type of <em class="parameter"><code>value</code></em> is <span class="type">gconstpointer</span> only to allow use of this
function with <span class="type">GHashTable</span>.  <em class="parameter"><code>value</code></em> must be a <span class="type">GVariant</span>.</p>
<div class="refsect3">
<a name="id-1.1.84.3.36.6"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>a basic <span class="type">GVariant</span> value as a <span class="type">gconstpointer</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.37"></a><h3>is-container?</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:is-container? self))
</pre></div>
<p>Checks if <em class="parameter"><code>value</code></em> is a container.</p>
<div class="refsect3">
<a name="id-1.1.84.3.37.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>a <span class="type">GVariant</span> instance</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.38"></a><h3>is-floating?</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:is-floating? self))
</pre></div>
<p>Checks whether <em class="parameter"><code>value</code></em> has a floating reference count.
</p>
<p>This function should only ever be used to assert that a given variant
is or is not floating, or for debug purposes. To acquire a reference
to a variant that might be floating, always use <code class="function">g_variant_ref_sink()</code>
or <code class="function">g_variant_take_ref()</code>.
</p>
<p>See <code class="function">g_variant_ref_sink()</code> for more information about floating reference
counts.</p>
<div class="refsect3">
<a name="id-1.1.84.3.38.6"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>a <span class="type">GVariant</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.39"></a><h3>is-normal-form?</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:is-normal-form? self))
</pre></div>
<p>Checks if <em class="parameter"><code>value</code></em> is in normal form.
</p>
<p>The main reason to do this is to detect if a given chunk of
serialised data is in normal form: load the data into a <span class="type">GVariant</span>
using <code class="function">g_variant_new_from_data()</code> and then use this function to
check.
</p>
<p>If <em class="parameter"><code>value</code></em> is found to be in normal form then it will be marked as
being trusted.  If the value was already marked as being trusted then
this function will immediately return <code class="constant">TRUE</code>.
</p>
<p>There may be implementation specific restrictions on deeply nested values.
GVariant is guaranteed to handle nesting up to at least 64 levels.</p>
<div class="refsect3">
<a name="id-1.1.84.3.39.7"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>a <span class="type">GVariant</span> instance</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.40"></a><h3>is-of-type?</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:is-of-type? self type))
</pre></div>
<p>Checks if a value has a type matching the provided type.</p>
<div class="refsect3">
<a name="id-1.1.84.3.40.4"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>a <span class="type">GVariant</span> instance</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>type</p></td>
<td class="parameter_description">
<p>a <span class="type">GVariantType</span></p>
<p>Passed as <code class="code">type</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.41"></a><h3>lookup-value</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:lookup-value self key expected-type))
</pre></div>
<p>Looks up a value in a dictionary <span class="type">GVariant</span>.
</p>
<p>This function works with dictionaries of the type a{s*} (and equally
well with type a{o*}, but we only further discuss the string case
for sake of clarity).
</p>
<p>In the event that <em class="parameter"><code>dictionary</code></em> has the type a{sv}, the <em class="parameter"><code>expected_type</code></em>
string specifies what type of value is expected to be inside of the
variant. If the value inside the variant has a different type then
<code class="constant">NULL</code> is returned. In the event that <em class="parameter"><code>dictionary</code></em> has a value type other
than v then <em class="parameter"><code>expected_type</code></em> must directly match the value type and it is
used to unpack the value directly or an error occurs.
</p>
<p>In either case, if <em class="parameter"><code>key</code></em> is not found in <em class="parameter"><code>dictionary</code></em>, <code class="constant">NULL</code> is returned.
</p>
<p>If the key is found and the value has the correct type, it is
returned.  If <em class="parameter"><code>expected_type</code></em> was specified then any non-<code class="constant">NULL</code> return
value will have this type.
</p>
<p>This function is currently implemented with a linear scan.  If you
plan to do many lookups then <span class="type">GVariantDict</span> may be more efficient.</p>
<div class="refsect3">
<a name="id-1.1.84.3.41.9"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>dictionary</p></td>
<td class="parameter_description">
<p>a dictionary <span class="type">GVariant</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>key</p></td>
<td class="parameter_description">
<p>the key to look up in the dictionary</p>
<p>Passed as <code class="code">key</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>expected_type</p></td>
<td class="parameter_description">
<p>a <span class="type">GVariantType</span>, or <code class="constant">NULL</code></p>
<p>Passed as <code class="code">expected-type</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.42"></a><h3>n-children</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:n-children self))
</pre></div>
<p>Determines the number of children in a container <span class="type">GVariant</span> instance.
This includes variants, maybes, arrays, tuples and dictionary
entries.  It is an error to call this function on any other type of
<span class="type">GVariant</span>.
</p>
<p>For variants, the return value is always 1.  For values with maybe
types, it is always zero or one.  For arrays, it is the length of the
array.  For tuples it is the number of tuple items (which depends
only on the type).  For dictionary entries, it is always 2
</p>
<p>This function is O(1).</p>
<div class="refsect3">
<a name="id-1.1.84.3.42.6"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>a container <span class="type">GVariant</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.43"></a><h3>print</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:print self type-annotate))
</pre></div>
<p>Pretty-prints <em class="parameter"><code>value</code></em> in the format understood by <code class="function">g_variant_parse()</code>.
</p>
<p>The format is described [here][gvariant-text].
</p>
<p>If <em class="parameter"><code>type_annotate</code></em> is <code class="constant">TRUE</code>, then type information is included in
the output.</p>
<div class="refsect3">
<a name="id-1.1.84.3.43.6"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>a <span class="type">GVariant</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>type_annotate</p></td>
<td class="parameter_description">
<p><code class="constant">TRUE</code> if type information should be included in
                the output</p>
<p>Passed as <code class="code">type-annotate</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.44"></a><h3>ref</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:ref self))
</pre></div>
<p>Increases the reference count of <em class="parameter"><code>value</code></em>.</p>
<div class="refsect3">
<a name="id-1.1.84.3.44.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>a <span class="type">GVariant</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.45"></a><h3>ref-sink</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:ref-sink self))
</pre></div>
<p><span class="type">GVariant</span> uses a floating reference count system.  All functions with
names starting with <code class="code">g_variant_new_</code> return floating
references.
</p>
<p>Calling <code class="function">g_variant_ref_sink()</code> on a <span class="type">GVariant</span> with a floating reference
will convert the floating reference into a full reference.  Calling
<code class="function">g_variant_ref_sink()</code> on a non-floating <span class="type">GVariant</span> results in an
additional normal reference being added.
</p>
<p>In other words, if the <em class="parameter"><code>value</code></em> is floating, then this call "assumes
ownership" of the floating reference, converting it to a normal
reference.  If the <em class="parameter"><code>value</code></em> is not floating, then this call adds a
new normal reference increasing the reference count by one.
</p>
<p>All calls that result in a <span class="type">GVariant</span> instance being inserted into a
container will call <code class="function">g_variant_ref_sink()</code> on the instance.  This means
that if the value was just created (and has only its floating
reference) then the container will assume sole ownership of the value
at that point and the caller will not need to unreference it.  This
makes certain common styles of programming much easier while still
maintaining normal refcounting semantics in situations where values
are not floating.</p>
<div class="refsect3">
<a name="id-1.1.84.3.45.7"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>a <span class="type">GVariant</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.46"></a><h3>store</h3>
<div class="informalexample"><pre class="programlisting">(define-values () (variant:store self data))
</pre></div>
<p>Stores the serialised form of <em class="parameter"><code>value</code></em> at <em class="parameter"><code>data</code></em>.  <em class="parameter"><code>data</code></em> should be
large enough.  See <code class="function">g_variant_get_size()</code>.
</p>
<p>The stored data is in machine native byte order but may not be in
fully-normalised form if read from an untrusted source.  See
<code class="function">g_variant_get_normal_form()</code> for a solution.
</p>
<p>As with <code class="function">g_variant_get_data()</code>, to be able to deserialise the
serialised variant successfully, its type and (if the destination
machine might be different) its endianness must also be available.
</p>
<p>This function is approximately O(n) in the size of <em class="parameter"><code>data</code></em>.</p>
<div class="refsect3">
<a name="id-1.1.84.3.46.7"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>the <span class="type">GVariant</span> to store</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>data</p></td>
<td class="parameter_description">
<p>the location to store the serialised data at</p>
<p>Passed as <code class="code">data</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.47"></a><h3>take-ref</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:take-ref self))
</pre></div>
<p>If <em class="parameter"><code>value</code></em> is floating, sink it.  Otherwise, do nothing.
</p>
<p>Typically you want to use <code class="function">g_variant_ref_sink()</code> in order to
automatically do the correct thing with respect to floating or
non-floating references, but there is one specific scenario where
this function is helpful.
</p>
<p>The situation where this function is helpful is when creating an API
that allows the user to provide a callback function that returns a
<span class="type">GVariant</span>.  We certainly want to allow the user the flexibility to
return a non-floating reference from this callback (for the case
where the value that is being returned already exists).
</p>
<p>At the same time, the style of the <span class="type">GVariant</span> API makes it likely that
for newly-created <span class="type">GVariant</span> instances, the user can be saved some
typing if they are allowed to return a <span class="type">GVariant</span> with a floating
reference.
</p>
<p>Using this function on the return value of the user's callback allows
the user to do whichever is more convenient for them.  The caller
will always receives exactly one full reference to the value: either
the one that was returned in the first place, or a floating reference
that has been converted to a full reference.
</p>
<p>This function has an odd interaction when combined with
<code class="function">g_variant_ref_sink()</code> running at the same time in another thread on
the same <span class="type">GVariant</span> instance.  If <code class="function">g_variant_ref_sink()</code> runs first then
the result will be that the floating reference is converted to a hard
reference.  If <code class="function">g_variant_take_ref()</code> runs first then the result will
be that the floating reference is converted to a hard reference and
an additional reference on top of that one is added.  It is best to
avoid this situation.</p>
<div class="refsect3">
<a name="id-1.1.84.3.47.9"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>a <span class="type">GVariant</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.48"></a><h3>unref</h3>
<div class="informalexample"><pre class="programlisting">(define-values () (variant:unref self))
</pre></div>
<p>Decreases the reference count of <em class="parameter"><code>value</code></em>.  When its reference count
drops to 0, the memory used by the variant is freed.</p>
<div class="refsect3">
<a name="id-1.1.84.3.48.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p>a <span class="type">GVariant</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.49"></a><h3>variant:new-variant</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-variant value))
</pre></div>
<p>Undocumented</p>
<div class="refsect3">
<a name="id-1.1.84.3.49.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">value</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.50"></a><h3>variant:new-uint64</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-uint64 value))
</pre></div>
<p>Undocumented</p>
<div class="refsect3">
<a name="id-1.1.84.3.50.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">value</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.51"></a><h3>variant:new-uint32</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-uint32 value))
</pre></div>
<p>Undocumented</p>
<div class="refsect3">
<a name="id-1.1.84.3.51.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">value</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.52"></a><h3>variant:new-uint16</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-uint16 value))
</pre></div>
<p>Undocumented</p>
<div class="refsect3">
<a name="id-1.1.84.3.52.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">value</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.53"></a><h3>variant:new-tuple</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-tuple children))
</pre></div>
<p>Undocumented</p>
<div class="refsect3">
<a name="id-1.1.84.3.53.4"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>children</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">children</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>n_children</p></td>
<td class="parameter_description">
<p></p>
<p>Inferred from <code class="code">children</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.54"></a><h3>variant:new-strv</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-strv strv))
</pre></div>
<p>Undocumented</p>
<div class="refsect3">
<a name="id-1.1.84.3.54.4"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>strv</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">strv</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>length</p></td>
<td class="parameter_description">
<p></p>
<p>Inferred from <code class="code">strv</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.55"></a><h3>variant:new-string</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-string string))
</pre></div>
<p>Undocumented</p>
<div class="refsect3">
<a name="id-1.1.84.3.55.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>string</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">string</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.56"></a><h3>variant:new-signature</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-signature signature))
</pre></div>
<p>Undocumented</p>
<div class="refsect3">
<a name="id-1.1.84.3.56.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>signature</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">signature</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.57"></a><h3>variant:new-objv</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-objv strv))
</pre></div>
<p>Undocumented</p>
<div class="refsect3">
<a name="id-1.1.84.3.57.4"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>strv</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">strv</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>length</p></td>
<td class="parameter_description">
<p></p>
<p>Inferred from <code class="code">strv</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.58"></a><h3>variant:new-object-path</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-object-path object-path))
</pre></div>
<p>Undocumented</p>
<div class="refsect3">
<a name="id-1.1.84.3.58.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>object_path</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">object-path</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.59"></a><h3>variant:new-maybe</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-maybe child-type child))
</pre></div>
<p>Undocumented</p>
<div class="refsect3">
<a name="id-1.1.84.3.59.4"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>child_type</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">child-type</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>child</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">child</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.60"></a><h3>variant:new-int64</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-int64 value))
</pre></div>
<p>Undocumented</p>
<div class="refsect3">
<a name="id-1.1.84.3.60.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">value</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.61"></a><h3>variant:new-int32</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-int32 value))
</pre></div>
<p>Undocumented</p>
<div class="refsect3">
<a name="id-1.1.84.3.61.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">value</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.62"></a><h3>variant:new-int16</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-int16 value))
</pre></div>
<p>Undocumented</p>
<div class="refsect3">
<a name="id-1.1.84.3.62.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">value</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.63"></a><h3>variant:new-handle</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-handle value))
</pre></div>
<p>Undocumented</p>
<div class="refsect3">
<a name="id-1.1.84.3.63.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">value</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.64"></a><h3>variant:new-from-data</h3>
<div class="informalexample"><pre class="programlisting">(define-values
  (%return)
  (variant:new-from-data type data trusted notify user-data))
</pre></div>
<p>Undocumented</p>
<div class="refsect3">
<a name="id-1.1.84.3.64.4"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>type</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">type</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>data</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">data</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>size</p></td>
<td class="parameter_description">
<p></p>
<p>Inferred from <code class="code">data</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>trusted</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">trusted</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>notify</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">notify</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>user_data</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">user-data</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.65"></a><h3>variant:new-from-bytes</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-from-bytes type bytes trusted))
</pre></div>
<p>Undocumented</p>
<div class="refsect3">
<a name="id-1.1.84.3.65.4"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>type</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">type</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>bytes</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">bytes</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>trusted</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">trusted</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.66"></a><h3>variant:new-fixed-array</h3>
<div class="informalexample"><pre class="programlisting">(define-values
  (%return)
  (variant:new-fixed-array element-type elements n-elements element-size))
</pre></div>
<p>Undocumented</p>
<div class="refsect3">
<a name="id-1.1.84.3.66.4"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>element_type</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">element-type</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>elements</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">elements</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>n_elements</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">n-elements</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>element_size</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">element-size</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.67"></a><h3>variant:new-double</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-double value))
</pre></div>
<p>Undocumented</p>
<div class="refsect3">
<a name="id-1.1.84.3.67.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">value</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.68"></a><h3>variant:new-dict-entry</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-dict-entry key value))
</pre></div>
<p>Undocumented</p>
<div class="refsect3">
<a name="id-1.1.84.3.68.4"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>key</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">key</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">value</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.69"></a><h3>variant:new-bytestring-array</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-bytestring-array strv))
</pre></div>
<p>Undocumented</p>
<div class="refsect3">
<a name="id-1.1.84.3.69.4"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>strv</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">strv</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>length</p></td>
<td class="parameter_description">
<p></p>
<p>Inferred from <code class="code">strv</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.70"></a><h3>variant:new-bytestring</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-bytestring string))
</pre></div>
<p>Undocumented</p>
<div class="refsect3">
<a name="id-1.1.84.3.70.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>string</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">string</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.71"></a><h3>variant:new-byte</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-byte value))
</pre></div>
<p>Undocumented</p>
<div class="refsect3">
<a name="id-1.1.84.3.71.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">value</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.72"></a><h3>variant:new-boolean</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-boolean value))
</pre></div>
<p>Undocumented</p>
<div class="refsect3">
<a name="id-1.1.84.3.72.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>value</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">value</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.73"></a><h3>variant:new-array</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:new-array child-type children))
</pre></div>
<p>Undocumented</p>
<div class="refsect3">
<a name="id-1.1.84.3.73.4"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>child_type</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">child-type</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>children</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">children</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>n_children</p></td>
<td class="parameter_description">
<p></p>
<p>Inferred from <code class="code">children</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.74"></a><h3>variant:is-object-path?</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:is-object-path? string))
</pre></div>
<p>Determines if a given string is a valid D-Bus object path.  You
should ensure that a string is a valid D-Bus object path before
passing it to <code class="function">g_variant_new_object_path()</code>.
</p>
<p>A valid object path starts with <code class="code">/</code> followed by zero or more
sequences of characters separated by <code class="code">/</code> characters.  Each sequence
must contain only the characters <code class="code">[A-Z][a-z][0-9]_</code>.  No sequence
(including the one following the final <code class="code">/</code> character) may be empty.</p>
<div class="refsect3">
<a name="id-1.1.84.3.74.5"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>string</p></td>
<td class="parameter_description">
<p>a normal C nul-terminated string</p>
<p>Passed as <code class="code">string</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.75"></a><h3>variant:is-signature?</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:is-signature? string))
</pre></div>
<p>Determines if a given string is a valid D-Bus type signature.  You
should ensure that a string is a valid D-Bus type signature before
passing it to <code class="function">g_variant_new_signature()</code>.
</p>
<p>D-Bus type signatures consist of zero or more definite <span class="type">GVariantType</span>
strings in sequence.</p>
<div class="refsect3">
<a name="id-1.1.84.3.75.5"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>string</p></td>
<td class="parameter_description">
<p>a normal C nul-terminated string</p>
<p>Passed as <code class="code">string</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.76"></a><h3>variant:parse</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:parse type text limit endptr))
</pre></div>
<p>Parses a <span class="type">GVariant</span> from a text representation.
</p>
<p>A single <span class="type">GVariant</span> is parsed from the content of <em class="parameter"><code>text</code></em>.
</p>
<p>The format is described [here][gvariant-text].
</p>
<p>The memory at <em class="parameter"><code>limit</code></em> will never be accessed and the parser behaves as
if the character at <em class="parameter"><code>limit</code></em> is the nul terminator.  This has the
effect of bounding <em class="parameter"><code>text</code></em>.
</p>
<p>If <em class="parameter"><code>endptr</code></em> is non-<code class="constant">NULL</code> then <em class="parameter"><code>text</code></em> is permitted to contain data
following the value that this function parses and <em class="parameter"><code>endptr</code></em> will be
updated to point to the first character past the end of the text
parsed by this function.  If <em class="parameter"><code>endptr</code></em> is <code class="constant">NULL</code> and there is extra data
then an error is returned.
</p>
<p>If <em class="parameter"><code>type</code></em> is non-<code class="constant">NULL</code> then the value will be parsed to have that
type.  This may result in additional parse errors (in the case that
the parsed value doesn't fit the type) but may also result in fewer
errors (in the case that the type would have been ambiguous, such as
with empty arrays).
</p>
<p>In the event that the parsing is successful, the resulting <span class="type">GVariant</span>
is returned. It is never floating, and must be freed with
<code class="function">g_variant_unref()</code>.
</p>
<p>In case of any error, <code class="constant">NULL</code> will be returned.  If <em class="parameter"><code>error</code></em> is non-<code class="constant">NULL</code>
then it will be set to reflect the error that occurred.
</p>
<p>Officially, the language understood by the parser is "any string
produced by <code class="function">g_variant_print()</code>".
</p>
<p>There may be implementation specific restrictions on deeply nested values,
which would result in a <code class="constant">G_VARIANT_PARSE_ERROR_RECURSION</code> error. <span class="type">GVariant</span> is
guaranteed to handle nesting up to at least 64 levels.</p>
<div class="refsect3">
<a name="id-1.1.84.3.76.13"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>type</p></td>
<td class="parameter_description">
<p>a <span class="type">GVariantType</span>, or <code class="constant">NULL</code></p>
<p>Passed as <code class="code">type</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>text</p></td>
<td class="parameter_description">
<p>a string containing a GVariant in text form</p>
<p>Passed as <code class="code">text</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>limit</p></td>
<td class="parameter_description">
<p>a pointer to the end of <em class="parameter"><code>text</code></em>, or <code class="constant">NULL</code></p>
<p>Passed as <code class="code">limit</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>endptr</p></td>
<td class="parameter_description">
<p>a location to store the end pointer, or <code class="constant">NULL</code></p>
<p>Passed as <code class="code">endptr</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.77"></a><h3>variant:parse-error-print-context</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:parse-error-print-context error source-str))
</pre></div>
<p>Pretty-prints a message showing the context of a <span class="type">GVariant</span> parse
error within the string for which parsing was attempted.
</p>
<p>The resulting string is suitable for output to the console or other
monospace media where newlines are treated in the usual way.
</p>
<p>The message will typically look something like one of the following:
</p>
<div class="informalexample"><pre class="programlisting">
unterminated string constant:
  (1, 2, 3, 'abc
            ^^^^
</pre></div>

<p>or
</p>
<div class="informalexample"><pre class="programlisting">
unable to find a common type:
  [1, 2, 3, 'str']
   ^        ^^^^^
</pre></div>

<p>The format of the message may change in a future version.
</p>
<p><em class="parameter"><code>error</code></em> must have come from a failed attempt to <code class="function">g_variant_parse()</code> and
<em class="parameter"><code>source_str</code></em> must be exactly the same string that caused the error.
If <em class="parameter"><code>source_str</code></em> was not nul-terminated when you passed it to
<code class="function">g_variant_parse()</code> then you must add nul termination before using this
function.</p>
<div class="refsect3">
<a name="id-1.1.84.3.77.11"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>error</p></td>
<td class="parameter_description">
<p>a <span class="type">GError</span> from the <span class="type">GVariantParseError</span> domain</p>
<p>Passed as <code class="code">error</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>source_str</p></td>
<td class="parameter_description">
<p>the string that was given to the parser</p>
<p>Passed as <code class="code">source-str</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.78"></a><h3>variant:parse-error-quark</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:parse-error-quark))
</pre></div>
<p>Undocumented</p>
</div>
<div class="refsect2">
<a name="id-1.1.84.3.79"></a><h3>variant:parser-get-error-quark</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (variant:parser-get-error-quark))
</pre></div>
<p>Same as <code class="function">g_variant_error_quark()</code>.</p>
</div>
</div>
</div>
<div class="footer">
<hr>Generated by GTK-Doc V1.33.1</div>
</body>
</html>
